package com.swak.pool;

import java.lang.ref.SoftReference;
import java.util.Collection;
import java.util.Iterator;
import java.util.Queue;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.stream.Stream;

class SoftReferenceQueue<T> implements Queue<T> {

	private Queue<SoftReference<T>> delegate;
	
	SoftReferenceQueue(Queue<SoftReference<T>> delegate) {
		this.delegate = delegate;
	}

	public void forEach(Consumer<? super T> action) {
		throw new UnsupportedOperationException();
	}

	public T poll() {
		T res;
		SoftReference<T> ref;
		while ((ref = delegate.poll()) != null) {
			if ((res = ref.get()) != null) {
				return res;
			}
		}
		return null;
	}

	public boolean add(T e) {
		return delegate.add(new SoftReference<T>(e));
	}

	public boolean offer(T e) {
		return delegate.offer(new SoftReference<T>(e));
	}

	public int size() {
		return delegate.size();
	}

	public boolean isEmpty() {
		return delegate.isEmpty();
	}

	public boolean contains(Object o) {
		return delegate.contains(o);
	}

	public void clear() {
		delegate.clear();
	}

	public boolean equals(Object o) {
		return delegate.equals(o);
	}

	public int hashCode() {
		return delegate.hashCode();
	}

	public T element() {
		throw new UnsupportedOperationException();
	}

	public T peek() {
		throw new UnsupportedOperationException();
	}

	public T remove() {
		throw new UnsupportedOperationException();
	}

	public Iterator<T> iterator() {
		throw new UnsupportedOperationException();
	}

	public Object[] toArray() {
		throw new UnsupportedOperationException();
	}

	@SuppressWarnings("hiding")
	public <T> T[] toArray(T[] a) {
		throw new UnsupportedOperationException();
	}

	@SuppressWarnings("hiding")
	public <T> T[] toArray(IntFunction<T[]> generator) {
		throw new UnsupportedOperationException();
	}

	public boolean remove(Object o) {
		throw new UnsupportedOperationException();
	}

	public boolean containsAll(Collection<?> c) {
		throw new UnsupportedOperationException();
	}

	public boolean addAll(Collection<? extends T> c) {
		throw new UnsupportedOperationException();
	}

	public boolean removeAll(Collection<?> c) {
		throw new UnsupportedOperationException();
	}

	public boolean removeIf(Predicate<? super T> filter) {
		throw new UnsupportedOperationException();
	}

	public boolean retainAll(Collection<?> c) {
		throw new UnsupportedOperationException();
	}

	public Spliterator<T> spliterator() {
		throw new UnsupportedOperationException();
	}

	public Stream<T> stream() {
		throw new UnsupportedOperationException();
	}

	public Stream<T> parallelStream() {
		throw new UnsupportedOperationException();
	}
}
